/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reportcenter.support.custom.binding;

/**
 *
 * @author renan_luz
 */
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import javax.swing.JComponent;
import org.springframework.binding.form.FormModel;
import org.springframework.richclient.form.binding.support.CustomBinding;
import reportcenter.support.custom.component.DirectoryChooserPanel;
import reportcenter.support.custom.component.FileChooserPanel;

public class DirectoryBinding extends CustomBinding {

    private final DirectoryChooserPanel directoryChooser;

    public DirectoryBinding(FormModel formModel, String formPropertyPath) {
        super(formModel, formPropertyPath, File.class);
        directoryChooser = new DirectoryChooserPanel();
    }

    @Override
    protected void valueModelChanged(Object newValue) {
        directoryChooser.setDirectoryChosen((File) newValue);
    }

    @Override
    protected JComponent doBindControl() {
        directoryChooser.addFileListener(new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent evt) {
                controlValueChanged(evt.getNewValue());
            }
        });
        return directoryChooser;
    }

    @Override
    protected void readOnlyChanged() {
        directoryChooser.setReadOnly(isReadOnly());
    }

    @Override
    protected void enabledChanged() {
        directoryChooser.setEnabled(isEnabled());
    }
}  
